package com.wisdom.smartbook.activity;


import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import com.wisdom.smartbook.R;
import com.wisdom.smartbook.app.MyApp;
import com.wisdom.smartbook.base.BaseActivity;
import com.wisdom.smartbook.permission.PermissionUtils;
import com.wisdom.smartbook.utils.ActivityManagerUtils;
import com.wisdom.smartbook.utils.KLog;
import com.wisdom.smartbook.utils.ToastUtils;


import java.util.List;

/**
 * 启动页
 */
public class SplashActivity extends BaseActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Activity启动后就锁定为启动时的方向

//        if(this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT){
//            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
////            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
//        }


        KLog.d("SplashActivity  onCreate(）");

    }


    @Override
    protected int getLayoutId() {
        return R.layout.activity_splash;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {
        KLog.d("checkPermissions()");
        PermissionUtils.getInstance().checkPermissions(this, new PermissionUtils.onPermissionsResultListener() {
            @Override
            public void onPermissionGranted() {
                mHandler.sendEmptyMessageDelayed(1, 1000);
            }

            @Override
            public void onPermissionDenied(List<String> permissionList, String permissionsHint) {
                ToastUtils.showShortSafe("必要权限被拒绝，应用退出！");
                ActivityManagerUtils.getInstance().exitApp();
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        PermissionUtils.getInstance().onDestroy();
    }

    Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
//            if (MyApp.getInstance().isX5Finish()) {
//                gotoMain();
//            } else {
//                mHandler.sendEmptyMessageDelayed(1, 1000);
//            }
                            gotoMain();

        }
    };

    public void gotoMain() {
        Intent intent = new Intent();
//        if (getApplicationInfo().processName.contains("student")) {
//            intent.setClass(this, MainActivity.class);
//        } else {
////            intent.setClass(this, TeacherHomeActivity.class);
//            intent.setClass(this, MainActivity.class);
//        }

        intent.setClass(this, MainActivityNew.class);

        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
        finish();
    }
}